package represent.expression;

import java.util.Collection;
import java.util.HashSet;

import metadata.schema.Schema;

import represent.Scan;
import represent.type.Type;

public class ConstantExpression extends Expression{

	private Type val;
	
	public ConstantExpression(Type c) {
	      val = c;
	   }
	
	public void addTableName(Schema schema) {
		// nothing to do
	}

	public boolean appliesTo(Schema sch) {
		return true;
	}

	 public String toString() {
		  if(alias == null)
			  return val.toString();
		  else
			  return val + " as " + alias;
	   }
	 
	public Type asConstant() {
		return val;
	}

	public String asFieldName() {
		throw new Error("should not be called");
	}

	public Type evaluate(Scan s) {
		return val;
	}

	public String getFieldName() {
		return toString();
	}

	public Collection<String> getNeededFields() {
		return new HashSet<String>();
	}

	public String getReferName() {
		if(alias == null)
			return toString();
		else
			return alias;
	}

	public String getType(Schema sch) {
		return val.getType();
	}

	public Type getVal(Scan s) {
		return val;
	}

	public boolean isConstant() {
		 return true;
	}

	public boolean isFieldName() {
		return false;
	}


}
